<?php
defined('IN_ADMIN') or exit('No permission resources.');
include PC_PATH.'modules'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.'header.tpl.php';

class content_tag {
	private $db;
	public function __construct() {
		$this->db = pc_base::load_model('content_model');
		$this->position = pc_base::load_model('position_data_model');
	}
	/**
	 * 初始化模型
	 * @param $catid
	 */
	public function set_modelid($catid) {
		static $CATS;
		$siteids = getcache('category_content','commons');
		if(!$siteids[$catid]) return false;
		$siteid = $siteids[$catid];
		if ($CATS[$siteid]) {
			$this->category = $CATS[$siteid];
		} else {
			$CATS[$siteid] = $this->category = getcache('category_content_'.$siteid,'commons');
		}
		if($this->category[$catid]['type']!=0) return false;
		$this->modelid = $this->category[$catid]['modelid'];
		$this->db->set_model($this->modelid);
		$this->tablename = $this->db->table_name;
		if(empty($this->category)) {
			return false;
		} else {
			return true;
		}
	}
	/**
	 * 分页统计
	 * @param $data
	 */
	public function count($data) {
		if($data['action'] == 'lists') {
			$catid = intval($data['catid']);
			if(!$this->set_modelid($catid)) return false;
			if(isset($data['where'])) {
				$sql = $data['where'];
			} else {
				if($this->category[$catid]['child']) {
					$catids_str = $this->category[$catid]['arrchildid'];
					$pos = strpos($catids_str,',')+1;
					$catids_str = substr($catids_str, $pos);
					$sql = "status=99 AND catid IN ($catids_str)";
				} else {
					$sql = "status=99 AND catid='$catid'";
				}
			}
			return $this->db->count($sql);
		}
	}
	
	/**
	 * 列表页标签
	 * @param $data
	 */
	public function lists($data) {
		$catid = intval($data['catid']);
		if(!$this->set_modelid($catid)) return false;
		if(isset($data['where'])) {
			$sql = $data['where'];
		} else {
			$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
			if($this->category[$catid]['child']) {
				$catids_str = $this->category[$catid]['arrchildid'];
				$pos = strpos($catids_str,',')+1;
				$catids_str = substr($catids_str, $pos);
				$sql = "status=99 AND catid IN ($catids_str)".$thumb;
			} else {
				$sql = "status=99 AND catid='$catid'".$thumb;
			}
		}
		$order = $data['order'];

		$return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');
						
		//调用副表的数据
		if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
			$ids = array();
			foreach ($return as $v) {
				if (isset($v['id']) && !empty($v['id'])) {
					$ids[] = $v['id'];
				} else {
					continue;
				}
			}
			if (!empty($ids)) {
				$this->db->table_name = $this->db->table_name.'_data';
				$ids = implode('\',\'', $ids);
				$r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');
				if (!empty($r)) {
					foreach ($r as $k=>$v) {
						if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
					}
				}
			}
		}
		return $return;
	}
	
	
	/**
	 * 栏目标签
	 * @param $data
	 */
	public function category($data) {
		$data['catid'] = intval($data['catid']);
		$array = array();
		$siteid = $data['siteid'] && intval($data['siteid']) ? intval($data['siteid']) : get_siteid();
		$categorys = getcache('category_content_'.$siteid,'commons');
		$site = siteinfo($siteid);
		$i = 1;
		is_array($categorys)?null:$categorys= array();
		foreach ($categorys as $catid=>$cat) {
			if($i>$data['limit']) break;
			if((!$cat['ismenu']) || $siteid && $cat['siteid']!=$siteid) continue;
			if (strpos($cat['url'], '://') === false) {
				$cat['url'] = substr($site['domain'],0,-1).$cat['url'];
			}
			if($cat['parentid']==$data['catid']) {
				$array[$catid] = $cat;
				$i++;
			}
		}
		return $array;
	}
	
}


pc_base::load_app_class('admin','admin',0);
class getNum extends admin{
	function __construct() {
        parent::__construct();
    }
	function getNum($table){
		$this->liuyan = pc_base::load_model($table.'_model');
		$data=$this->liuyan->select();
		$num=count($data);
		return $num;
	}
}
// 留言统计
$liuyan=new getNum;
$liuyan_num=$liuyan->getNum('liuyan');




// 数据统计（新闻）
$news=new content_tag;
$news_data['catid']=5;
$news_arr=$news->lists($news_data);
$news_num=count($news_arr);
// 数据统计（产品）
$product=new content_tag;
$product_data['catid']=2;
$product_arr=$news->lists($product_data);
$product_num=count($product_arr);
// 站点统计（IP）
$countIp=file_get_contents("countIp.txt");
$arr_ip=explode(",",$countIp);
$sum_ip=count($arr_ip)-1;
$time1=time()-3600*7;
$time2=time()-3600*6;
$time3=time()-3600*5;
$time4=time()-3600*4;
$time5=time()-3600*3;
$time6=time()-3600*2;
$time7=time()-3600*1;
$time8=time()-3600*0;
$data_ip=array(0,0,0,0,0,0,0);
foreach($arr_ip as $key => $value){
	$time=substr($value,0,10);
	if($time<=$time2 && $time>$time1){
		$data_ip[0]++;
	}elseif($time<=$time3 && $time>$time2){
		$data_ip[1]++;
	}elseif($time<=$time4 && $time>$time3){
		$data_ip[2]++;
	}elseif($time<=$time5 && $time>$time4){
		$data_ip[3]++;
	}elseif($time<=$time6 && $time>$time5){
		$data_ip[4]++;
	}elseif($time<=$time7 && $time>$time6){
		$data_ip[5]++;
	}elseif($time<=$time8 && $time>$time7){
		$data_ip[6]++;
	}
}
// 站点统计（PV）
$countPvTime=file_get_contents("countPvTime.txt");
$arr_pv=explode(",",$countPvTime);
$sum_pv=count($arr_pv)-1;
$data_pv=array(0,0,0,0,0,0,0);
foreach($arr_pv as $key => $value){
	$time=substr($value,0,10);
	if($time<=$time2 && $time>$time1){
		$data_pv[0]++;
	}elseif($time<=$time3 && $time>$time2){
		$data_pv[1]++;
	}elseif($time<=$time4 && $time>$time3){
		$data_pv[2]++;
	}elseif($time<=$time5 && $time>$time4){
		$data_pv[3]++;
	}elseif($time<=$time6 && $time>$time5){
		$data_pv[4]++;
	}elseif($time<=$time7 && $time>$time6){
		$data_pv[5]++;
	}elseif($time<=$time8 && $time>$time7){
		$data_pv[6]++;
	}
}
// echo $data_pv;
// 站点统计（UV）
$countUv=file_get_contents("countUv.txt");
$arr_uv=explode(",",$countUv);
$sum_uv=count($arr_uv)-1;
$data_uv=array(0,0,0,0,0,0,0);
foreach($arr_uv as $key => $value){
	$time=substr($value,0,10);
	if($time<=$time2 && $time>$time1){
		$data_uv[0]++;
	}elseif($time<=$time3 && $time>$time2){
		$data_uv[1]++;
	}elseif($time<=$time4 && $time>$time3){
		$data_uv[2]++;
	}elseif($time<=$time5 && $time>$time4){
		$data_uv[3]++;
	}elseif($time<=$time6 && $time>$time5){
		$data_uv[4]++;
	}elseif($time<=$time7 && $time>$time6){
		$data_uv[5]++;
	}elseif($time<=$time8 && $time>$time7){
		$data_uv[6]++;
	}
}
$data_ip=implode(",",$data_ip);
$data_uv=implode(",",$data_uv);
$data_pv=implode(",",$data_pv);
// echo $data_uv;



?>
<div id="main_frameid" class="pad-10 display" style="_margin-right:-12px;_width:98.9%;">
<script type="text/javascript">
$(function(){if ($.browser.msie && parseInt($.browser.version) < 7) $('#browserVersionAlert').show();});
</script>
<script src="/statics/js/echarts.common.min.js"></script>
<div class="explain-col mb10" style="display:none" id="browserVersionAlert">
<?php echo L('ie8_tip')?></div>




 


<div class="col-2 lf mr10" style="width:48%">
	<div id="main" style="width: 520px;height:300px;"></div>
</div>
<div class="col-2 col-auto">
	<h6>站点统计</h6>
	<div class="content" style="color:#ff0000;">
	<p>访客IP统计：<?php echo $sum_ip;?></p>
	<p>访客PV统计：<?php echo $sum_pv;?></p>
	<p>访客UV统计：<?php echo $sum_uv;?></p>
	</div>
</div>
    




<div class="bk10"></div>
<div class="col-2 lf mr10" style="width:48%">
<?php
$ccache = getcache('category_content_1','commons');

if(module_exists('member') && is_array($ccache)) { ?>
	<h6><?php echo L('main_shortcut')?></h6>
	<div class="content" id="admin_panel">
		<a href="index.php?m=webman&c=banner&a=init&pc_hash=<?=$_SESSION['pc_hash']?>">轮播图管理</a>
		<a href="index.php?m=webman&c=index&a=liuyan&pc_hash=<?=$_SESSION['pc_hash']?>">网站留言</a>

		<?php foreach($adminpanel as $v) {?>
		<span>
			[<a target="right" href="<?php echo $v['url'].'&menuid='.$v['menuid'];?>&pc_hash=<?php echo $_SESSION['pc_hash'];?>"><?php echo L($v['name'])?></a>]
		</span>
	<?php }?>
	</div>
<?php } else { ?>
	<h6>Update Caches</h6>
	<div class="content" id="update_tips" style="height:90px; overflow:auto;"><ul id="file" class="sbul">
<div class="pad-10">
<form action="?m=admin&c=cache_all&a=init&pc_hash=<?php echo $_SESSION['pc_hash'];?>" target="cache_if" method="post" id="myform" name="myform">
  <input type="hidden" name="dosubmit" value="1">
</form>
<iframe id="cache_if" name="cache_if" class="ifm" width="0" height="0"></iframe>
</div>
<script type="text/javascript">
document.myform.submit();
function addtext(data) {
	$('#file').append(data);
	document.getElementById('update_tips').scrollTop = document.getElementById('update_tips').scrollHeight;
}
</script>
	</div>
<?php }?>
</div>
<div class="col-2 col-auto">
	<h6>数据统计</h6>
	<div class="content">
	新闻数量：<?php echo $news_num?><br />
		
	产品数量：<?php echo $product_num?><br />
		
	</div>
</div>
<div class="bk10">


</div>



    <div class="bk10"></div>
</div>


<script type="text/javascript">
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('main'));

	// 指定图表的配置项和数据
    var option = {
    title: {
        text: '过去7小时访客分析'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data:['IP','UV','PV']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['<?php echo date("H",time()-3600*7)?>-<?php echo date("H",time()-3600*6)?>','<?php echo date("H",time()-3600*6)?>-<?php echo date("H",time()-3600*5)?>','<?php echo date("H",time()-3600*5)?>-<?php echo date("H",time()-3600*4)?>','<?php echo date("H",time()-3600*4)?>-<?php echo date("H",time()-3600*3)?>','<?php echo date("H",time()-3600*3)?>-<?php echo date("H",time()-3600*2)?>','<?php echo date("H",time()-3600*2)?>-<?php echo date("H",time()-3600*1)?>','<?php echo date("H",time()-3600*1)?>-<?php echo date("H",time()-3600*0)?>']
    },
    yAxis: {
        type: 'value',
		// splitArea: {show: true} 
    },
    series: [
        {
            name:'IP',
            type:'line',
            stack: 'IP',
            data:[<?php echo $data_ip;?>]
        },
        {
            name:'UV',
            type:'line',
            stack: 'UV',
            data:[<?php echo $data_uv;?>]
        },
        {
            name:'PV',
            type:'line',
            stack: 'PV',
            data:[<?php echo $data_pv;?>]
        }
    ]
};

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>



</body></html>